﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam2.Entity;
using MockPrjTeam2.Biz;

namespace MockPrjTeam2.Pages.Views
{
    public partial class SearchBussiness : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            ShowAllBussiness();
        }
        
        private void ShowAllBussiness()
        {
            var listBuss = new List<Bussiness>();
            var biz = new BussinessBiz();
            listBuss = biz.getAllBussinessByKey(string.Empty,string.Empty);

            GVSearchBussiness.DataSource = listBuss;
            GVSearchBussiness.DataBind();
        }

        protected void btSearch_Click(object sender, EventArgs e)
        {
            var listType = new List<Bussiness>();
            var getType = new BussinessBiz();
            listType = getType.getAllBussinessByKey(Convert.ToString(txtBussName.Text), Convert.ToString(txtSic.Text));
            if (listType != null)
            {
                GVSearchBussiness.DataSource = listType;
                GVSearchBussiness.DataBind();
            }      
        }
        protected void btAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Forms/AddBussinessType.aspx?add=ok");
        }

        protected void GVSearchBussiness_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GVSearchBussiness.PageIndex = e.NewPageIndex;
            ShowAllBussiness();
        }

        protected void GVSearchBussiness_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                Response.Redirect("../Forms/AddBussinessType.aspx?update=ok&BussinessID="+ e.CommandArgument);
            }   
        }
    }
}